package vn.qnamuni.calendar.adapters;

import vn.qnamuni.calendar.activity.R;
import vn.qnamuni.calendar.utils.GetDay;
import android.content.Context;
import android.database.Cursor;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CursorAdapter;
import android.widget.TextView;

public class MyCursorAdapter extends CursorAdapter {
	public MyCursorAdapter(Context context, Cursor c) {
		super(context, c, false);
	}

	@Override
	public void bindView(View view, Context context, Cursor cursor) {
		// name view
		TextView nameTextView = (TextView) view.findViewById(R.id.name_view);
		nameTextView.setText(cursor.getString(1));

		// date
		TextView mTextView = (TextView) view.findViewById(R.id.date_view);
		mTextView.setText(GetDay.getUI(cursor.getString(2)));
	}

	@Override
	public View newView(Context context, Cursor cursor, ViewGroup parent) {
		LayoutInflater inflater = LayoutInflater.from(parent.getContext());
		View view = inflater.inflate(R.layout.view_list_item, parent, false);
		return view;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		View view = super.getView(position, convertView, parent);
		if (position %2 == 0) {
			view.setBackgroundColor(Color.parseColor("#EFEFEF"));
		} else {
			view.setBackgroundColor(Color.parseColor("#DADADA"));
		}
		return view; 
	}
}
